package chat;

import java.io.OutputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2024-09-12
 * Time: 18:49
 */
public class Server {
    public static void main(String[] args) throws Exception {
        // 创建一个服务器
        ServerSocket server = new ServerSocket(8888);

        System.out.println("服务器创建成功==>等待客户端连接......");

        // 等待客户端连接
        Socket socket = null;
        while((socket = server.accept())!=null){
//            Server.list.add(socket);
//            System.out.println(Server.list.size());
//            new ServerThread(socket).start();
            System.out.println("连接成功");
            InputStream inputStream = socket.getInputStream();
            byte[] b = new byte[1024];
            int len;
            while ((len=inputStream.read(b))!=-1) {
                System.out.println(new String(b,0,len));
            }
//            OutputStream outputStream = socket.getOutputStream();
//            outputStream.write("发送成功".getBytes());
//            outputStream.flush();
        }



